<?php
/**
 * Created by PhpStorm.
 * User: bzhang
 * Date: 17-8-14
 * Time: 下午2:08
 */

namespace App\Error;


use Cake\Core\Configure;
use Cake\Error\ExceptionRenderer;
use Cake\Network\Exception\HttpException;
use Exception;
use PDOException;

class AppExceptionRenderer extends ExceptionRenderer
{

    protected function _template(Exception $exception, $method, $code)
    {
        if($exception->getCode() !== 200){
            return $this->template = 'error404';
        }


        $exception = $this->_unwrap($exception);
        $isHttpException = $exception instanceof HttpException;

        if (!Configure::read('debug') && !$isHttpException || $isHttpException) {
            $template = 'error500';
            if($code == 404){
                $template = 'error404';
            }else if ($code < 500) {
                $template = 'error400';
            }

            return $this->template = $template;
        }

        $template = $method ? 'error404' : 'error500';

        if ($exception instanceof PDOException) {
            $template = 'pdo_error';
        }

        if($exception->getCode() !== 200){
            $template = 'error404';
        }

        echo 'There has been an error!';
        return $this->template = $template;


    }


}